package com.oceansoft.mobile.econsole.modules.weixin.controller;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.oceansoft.mobile.econsole.common.constant.Constant;
import com.oceansoft.mobile.econsole.common.util.FileUtils;
import com.oceansoft.mobile.econsole.common.util.StringUtils;
import com.oceansoft.mobile.econsole.common.util.encrypt.DesAPPUtils;
import com.oceansoft.mobile.econsole.modules.api.entity.CarType;
import com.oceansoft.mobile.econsole.modules.base.controller.BaseController;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.complaint.entity.ComplaintReport;
import com.oceansoft.mobile.econsole.modules.member.entity.WtMember;
import com.oceansoft.mobile.econsole.modules.member.service.IWtMemberService;
import com.oceansoft.mobile.econsole.modules.weixin.config.WxFactory;
import com.oceansoft.mobile.econsole.modules.weixin.entity.*;
import com.oceansoft.mobile.econsole.modules.weixin.service.WeixinQueryService;
import com.oceansoft.mobile.econsole.weixin.api.OauthAPI;
import com.oceansoft.mobile.econsole.weixin.api.enums.OauthScope;
import com.oceansoft.mobile.econsole.weixin.api.response.GetSignatureResponse;
import com.oceansoft.mobile.econsole.weixin.controller.WeixinController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.misc.BASE64Decoder;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.*;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Created by zeng on 2016/8/8.
 */
@Controller
@RequestMapping("weixinquery")
public class WeixinQueryController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(WeixinController.class);

    @Resource
    private WeixinQueryService weixinQueryService;

    @Resource
    private IWtMemberService wtMemberService;

    /**
     * 跳转电子警察分布页面
     */
    @RequestMapping(value = "dzjcfbym", method = GET)
    public ModelAndView gotodzjcfbym() throws Exception {
        ModelAndView mv = new ModelAndView();
        List<Dzjcfb> dzjcfbList = weixinQueryService.getDzjcfbList();
        mv.addObject("dzjcfbList", dzjcfbList);
        mv.setViewName("weixin/weixinquery/dzjcfbym");
        return mv;
    }

    /**
     * 跳转违法代码查询页面
     */
    @RequestMapping(value = "wfdmym", method = GET)
    public ModelAndView gotowfdmym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/wfdmym");
        return mv;
    }

    /**
     * 违法代码
     */
    @RequestMapping(value = "wfdm", method = GET)
    @ResponseBody
    public Wfdm getWfdm(HttpServletRequest request) {
        String dm = request.getParameter("dm").toString();
        Wfdm wfdm = weixinQueryService.getWfdm(dm);
        return wfdm;
    }

    /**
     * 跳转处罚机关代码查询页面
     */
    @RequestMapping(value = "cfjgdmym", method = GET)
    public ModelAndView gotocfjgdmym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/cfjgdmym");
        return mv;
    }

    /**
     * 处罚机关代码
     */
    @RequestMapping(value = "cfjgdm", method = GET)
    @ResponseBody
    public Cfjgdm getCfjgdm(HttpServletRequest request) {
        String dm = request.getParameter("dm").toString();
        Cfjgdm cfjgdm = weixinQueryService.getCfjgdm(dm);
        return cfjgdm;
    }

    /**
     * 跳转保安员考试成绩查询页面
     */
    @RequestMapping(value = "baykscjym", method = GET)
    public ModelAndView gotobaykscjym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/baykscjym");
        return mv;
    }

    /**
     * 保安员考试成绩
     */
    @RequestMapping(value = "baykscj", method = GET)
    @ResponseBody
    public Baykscj getBaykscj(HttpServletRequest request) {
        String zkzh = request.getParameter("zkzh").toString();
        Baykscj baykscj = weixinQueryService.getBaykscj(zkzh);
        return baykscj;
    }

    /**
     * 跳转户籍分局查询页面
     */
    @RequestMapping(value = "hjfjym", method = GET)
    public ModelAndView gotohjfjym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/hjfjym");
        return mv;
    }

    /**
     * 户籍分局
     */
    @RequestMapping(value = "hjfj", method = GET)
    @ResponseBody
    public Hjfj getFj(HttpServletRequest request) {
        String pcs = request.getParameter("pcs").toString();
        String jd = request.getParameter("jd").toString();
        String sq = request.getParameter("sq").toString();
        Hjfj hjfj = weixinQueryService.getFj(pcs, jd, sq);
        return hjfj;
    }

    /**
     * 跳转到投诉建议页面
     */
    @RequestMapping(value = "tsjyym", method = GET)
    public ModelAndView gototsjyym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/tsjyym");
        return mv;
    }

    /**
     * 跳转到局长信箱--使用须知页面
     */
    @RequestMapping(value = "tsjyjzxxym")
    public String goToMailBoxPage(Model model, HttpServletRequest request) {
        model.addAttribute("userGuid", request.getParameter("userGuid"));
        return "weixin/weixinquery/mailnotice";
    }

    /**
     * 跳转到投诉建议-局长信箱页面
     */
    @RequestMapping(value = "gotomailbox", method = GET)
    public String gototsjyjzxxym(Model model, HttpServletRequest request) throws Exception {
        String userGuid = request.getParameter("userGuid");
//        String userGuid = "e8354342-0efa-4f4c-8cb0-13248459fbc3";
        WtMember wtMember;
        String ly;
        if (Strings.isNullOrEmpty(userGuid)) {
            wtMember = getWxMemberSession();
            ly = "W";

        } else {
            wtMember = wtMemberService.getWtMemberByUserGuid(userGuid);
            ly = "A";
        }
        model.addAttribute("telephone", wtMember.getUserName());

        //得到受理编号
        String slbh = weixinQueryService.getSlbh(com.oceansoft.mobile.econsole.modules.weixin.config.Constant.TSJY_JZXX);
        model.addAttribute("slbh", slbh);
        model.addAttribute("userGuid", wtMember.getGuid());
        model.addAttribute("today", new Date());
        model.addAttribute("ly", ly);
        model.addAttribute("aliasName", wtMember.getAliasName());//真实姓名
        String userCode = wtMember.getUserCode();//身份证号码

        if (!Strings.isNullOrEmpty(userCode) && !com.oceansoft.mobile.econsole.modules.weixin.config.Constant.isIDCard(userCode)) {
            userCode = DesAPPUtils.decrypt(wtMember.getUserCode());//从用户中获得身份证号码
        }
        model.addAttribute("idCard", userCode);

        return "weixin/weixinquery/tsjyjzxxym";
    }

    /**
     * 保存投诉建议-局长信箱信息
     */
    @ResponseBody
    @RequestMapping(value = "savetsjyjzxx", method = POST)
    public Result savetsjyjzxx(@RequestBody Tsjy tsjy) throws Exception {
        tsjy.setGuid(UUID.randomUUID().toString().replace("-", ""));
        tsjy.setXjorgid("230600000000");
        tsjy.setXjorgname("大庆市公安局");
        return weixinQueryService.savetsjyjzxx(tsjy);
    }

    /**
     * 跳转到投诉建议-警风警纪监督员意见建议页面
     */
    @RequestMapping(value = "tsjyjfjjym", method = GET)
    public ModelAndView gototsjyjfjjym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("telephone", getWxMemberSession().getUserName());
        mv.setViewName("weixin/weixinquery/tsjyjfjjym");
        return mv;
    }

    /**
     * 保存投诉建议-警风警纪监督员意见建议信息
     */
    @ResponseBody
    @RequestMapping(value = "savetsjyjfjj", method = GET)
    public Object savetsjyjfjj(HttpServletRequest request) throws Exception {
        Tsjy tsjy = new Tsjy();
        tsjy.setXjusername(request.getParameter("xm").toString());
        tsjy.setXjuserphone(request.getParameter("sjhm").toString());
        tsjy.setXjtitle(request.getParameter("yjzt").toString());
        tsjy.setXjcontent(request.getParameter("yjjy").toString());
        tsjy.setLx(request.getParameter("tsjylx").toString());
        tsjy.setLy(request.getParameter("ly").toString());
        tsjy.setXjuserguid(getWxMemberSession().getGuid());
        tsjy.setXjorgid("211300080000");
        tsjy.setXjorgname("辽宁省大庆市公安局纪委");
        tsjy.setXjtype(" ");
        return JSONObject.parseObject("{'guid':'" + weixinQueryService.savetsjyjfjj(tsjy) + "'}");
    }

    /**
     * 跳转快撤理赔页面
     */
    @RequestMapping(value = "kclpym", method = GET)
    public ModelAndView gotokclpym(HttpServletRequest request) throws Exception {
        String pt = request.getParameter("pt") == null ? "" : request.getParameter("pt").toString();
        ModelAndView mv = new ModelAndView();
        mv.addObject("pt", pt);
        mv.setViewName("weixin/weixinquery/kclpym");
        return mv;
    }

    /**
     * 保存快撤理赔
     */
    @ResponseBody
    @RequestMapping(value = "savekclp", method = POST)
    public boolean savekclp(HttpServletRequest request,
                            @RequestParam("address") String address,
                            @RequestParam("jwd") String jwd,
                            @RequestParam("Base64-1") String base641,
                            @RequestParam("Base64-2") String base642,
                            @RequestParam("Base64-3") String base643,
                            @RequestParam("suff1") String suff1,
                            @RequestParam("suff2") String suff2,
                            @RequestParam("suff3") String suff3,
                            @RequestParam("size1") String size1,
                            @RequestParam("size2") String size2,
                            @RequestParam("size3") String size3) throws Exception {

        String tel = getWxMemberSession().getUserName();
        String userGuid = getWxMemberSession().getGuid();
        String accidentId = weixinQueryService.getSlbh(com.oceansoft.mobile.econsole.modules.weixin.config.Constant.KCLP);

        KclpInfo kclpInfo = new KclpInfo();
        kclpInfo.setTelA(tel);
        kclpInfo.setUserId(userGuid);
        kclpInfo.setPosition(address);
        kclpInfo.setCoordinate(jwd);
        kclpInfo.setAccidentId(accidentId);

        List<KclpPhoto> kclpPhotoList = new ArrayList<>();
        for (int i = 1; i < 4; i++) {
            KclpPhoto kclpPhoto = new KclpPhoto();
            kclpPhoto.setPosition(address);
            kclpPhoto.setCoordinate(jwd);
            kclpPhoto.setUserId(userGuid);
            kclpPhoto.setAccidentId(accidentId);

            String photoGuid = UUID.randomUUID().toString().replace("-", "");
            kclpPhoto.setPhotoGuid(photoGuid);

            kclpPhoto.setPhotoType(i + 4);
            String time = weixinQueryService.getTime();
            String filePath = configInfo.getBizDir() + File.separator + userGuid + File.separator + time + File.separator
                    + "traffice" + File.separator + photoGuid;

            if (i == 1) {
                if (!StringUtils.isEmpty(base641)) {
                    base641 = base641.substring(base641.lastIndexOf(",") + 1, base641.length()).trim();
                    String newFileName = photoGuid + suff1;
                    String bizParentDir = configInfo.getBizDayDirRelPath(userGuid, configInfo.getTrafficeDir());
                    String imgUrl = String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir);

                    BASE64Decoder decoder = new BASE64Decoder();
                    FileOutputStream out = new FileOutputStream(FileUtils.createFile(new File(imgUrl), newFileName));
                    byte[] decoderBytes = decoder.decodeBuffer(base641);
                    out.write(decoderBytes);
                    out.flush();
                    out.close();

                    kclpPhoto.setFileContent(decoderBytes);
                }

                kclpPhoto.setPhotoSize(Integer.valueOf(size1));
                kclpPhoto.setSuffix(suff1);
                kclpPhoto.setFilePath(filePath + suff1);
            } else if (i == 2) {
                if (!StringUtils.isEmpty(base642)) {
                    base642 = base642.substring(base642.lastIndexOf(",") + 1, base642.length()).trim();
                    String newFileName = photoGuid + suff2;
                    String bizParentDir = configInfo.getBizDayDirRelPath(userGuid, configInfo.getTrafficeDir());
                    String imgUrl = String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir);

                    BASE64Decoder decoder = new BASE64Decoder();
                    FileOutputStream out = new FileOutputStream(FileUtils.createFile(new File(imgUrl), newFileName));
                    byte[] decoderBytes = decoder.decodeBuffer(base641);
                    out.write(decoderBytes);
                    out.flush();
                    out.close();

                    kclpPhoto.setFileContent(decoderBytes);
                }

                kclpPhoto.setPhotoSize(Integer.valueOf(size2));
                kclpPhoto.setSuffix(suff2);
                kclpPhoto.setFilePath(filePath + suff2);
            } else {
                if (!StringUtils.isEmpty(base643)) {
                    base643 = base643.substring(base643.lastIndexOf(",") + 1, base643.length()).trim();
                    String newFileName = photoGuid + suff3;
                    String bizParentDir = configInfo.getBizDayDirRelPath(userGuid, configInfo.getTrafficeDir());
                    String imgUrl = String.format("%s/%s", configInfo.getFileUploadRootPath(), bizParentDir);

                    BASE64Decoder decoder = new BASE64Decoder();
                    FileOutputStream out = new FileOutputStream(FileUtils.createFile(new File(imgUrl), newFileName));
                    byte[] decoderBytes = decoder.decodeBuffer(base641);
                    out.write(decoderBytes);
                    out.flush();
                    out.close();

                    kclpPhoto.setFileContent(decoderBytes);
                }

                kclpPhoto.setPhotoSize(Integer.valueOf(size3));
                kclpPhoto.setSuffix(suff3);
                kclpPhoto.setFilePath(filePath + suff3);
            }

            kclpPhotoList.add(kclpPhoto);
        }

        return weixinQueryService.savekclp(kclpInfo, kclpPhotoList);
    }

    /**
     * 跳转到强制报废页面
     */
    @RequestMapping(value = "qzbfym", method = GET)
    public ModelAndView gotoqzbfym(HttpServletRequest request) throws Exception {
        ModelAndView mv = new ModelAndView();

        // 获取车辆类型
        Map<String, String> map = (Map<String, String>) request.getSession().getServletContext().getAttribute(Constant.DICT_CAR_TYPE);
        if (map.size() > 0) {
            List<CarType> list = new ArrayList<>();
            for (String key : map.keySet()) {
                CarType carType = new CarType();
                carType.setCode(key);
                carType.setName(map.get(key));
                list.add(carType);
            }
            mv.addObject("list", list);
        }

        mv.setViewName("weixin/weixinquery/qzbfym");
        return mv;
    }

    /**
     * 跳转到微信举报页面
     */
    @RequestMapping(value = "wxjbym", method = GET)
    public ModelAndView gotowxjbym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("weixin/weixinquery/wxjbym");
        return mv;
    }

    /**
     * 跳转到线索举报--使用须知页面
     */
    @RequestMapping(value = "wxjbxsjbym", method = GET)
    public ModelAndView gotoReportPage(Model model, HttpServletRequest request) {
        // 微信端
        if("W".equals(request.getParameter("pt"))) {
            model.addAttribute("pt",request.getParameter("pt"));
          if (null != getWxMemberSession()) {
                model.addAttribute("returnUrl",WxFactory.SYHOST+"/weixinquery/gotoreport?pt="+request.getParameter("pt"));
                return new ModelAndView("weixin/weixinquery/reportnotice");
           } else {
               OauthAPI oauthAPI = WxFactory.buildOauthAPI();
                return new ModelAndView("redirect:" + oauthAPI.getOauthPageUrl(WxFactory.PERCENTER_OAUTH_URL, OauthScope.SNSAPI_BASE, "123"));
            }
        }else{//App端
            model.addAttribute("aUserGuid",request.getParameter("userguid"));
            model.addAttribute("aUserName",request.getParameter("username"));
            model.addAttribute("aCurrentMemberMobile",request.getParameter("currentMemberMobile"));
            model.addAttribute("pt",request.getParameter("pt"));
            model.addAttribute("returnUrl",WxFactory.SYHOST+"/weixinquery/gotoreport?pt="+request.getParameter("pt")+"&aUserGuid="+request.getParameter("userguid")+"&aUserName="+request.getParameter("username")+"&aCurrentMemberMobile="+request.getParameter("currentMemberMobile"));
            return new ModelAndView("weixin/weixinquery/reportnotice");
        }
    }

    /**
     * 跳转线索举报前的5个分类
     */
    @RequestMapping(value = "gotoreport5", method = GET)
    public String gotowxxsjb5() {
        return "weixin/weixinquery/xsjb5";
    }

    /**
     * 跳转到微信举报-线索举报页面
     */
    @RequestMapping(value = "gotoreportpage", method = GET)
    public ModelAndView gotowxjbxsjbym(Model model, @RequestParam("type") String type) throws Exception {
        ModelAndView mv = new ModelAndView();
//        mv.addObject("aliasName", getWxMemberSession().getAliasName());
//        mv.addObject("telephone", getWxMemberSession().getUserName());
//
//        String userCode = getWxMemberSession().getUserCode();
//
//        if(!Strings.isNullOrEmpty(userCode) && !com.oceansoft.mobile.econsole.modules.weixin.config.Constant.isIDCard(userCode)){
//            userCode = DesAPPUtils.decrypt(getWxMemberSession().getUserCode());
//        }
//
//        mv.addObject("idCard", userCode);
/*
        mv.addObject("aliasName", "shaomin");
        mv.addObject("telephone", "12599999999");
        mv.addObject("idCard", "9999999999999");*/
        model.addAttribute("guid", UUID.randomUUID().toString().replaceAll("-", ""));
        String title = "";
        List<CluesModel> listType = new ArrayList<>();
        if ("yw".equals(type)) {
            title = "交警业务举报";
            listType = weixinQueryService.getXsjblx("jgyw");
        } else if ("aj".equals(type)) {
            title = "案件举报";
            listType = weixinQueryService.getXsjblx("ajjb");
        } else if ("xf".equals(type)) {
            title = "消防举报";
            listType = weixinQueryService.getXsjblx("xfjb");
        } else if ("za".equals(type)) {
            title = "治安举报";
            listType = weixinQueryService.getXsjblx("zajb");
        } else {
            title = "反恐举报";
            listType = weixinQueryService.getXsjblx("fkjb");
        }
        model.addAttribute("title", title);
        model.addAttribute("type", type);
        model.addAttribute("listType", listType);
        mv.setViewName("weixin/weixinquery/wxjbxsjbym");
        return mv;
    }


    /**
     * 跳转到线索举报页面
     */
    @RequestMapping(value = "gotoreport", method = GET)
    public ModelAndView gotowxxsjbym(Model model, HttpServletRequest request) throws Exception {
        ModelAndView mv = new ModelAndView();
        model.addAttribute("guid", UUID.randomUUID().toString().replaceAll("-", ""));
        String title = "";
        model.addAttribute("title", "微报警");
        //TODO
        if("W".equals(request.getParameter("pt"))){//微信端
             model.addAttribute("currentMemberMobile", getWxMemberSession().getMobile());
             model.addAttribute("userguid", getWxMemberSession().getGuid());
             model.addAttribute("username", getWxMemberSession().getUserName());
/*             model.addAttribute("currentMemberMobile", "15806185251");
             model.addAttribute("userguid", "123");
             model.addAttribute("username", "we");*/
        }else{//APP端
            model.addAttribute("currentMemberMobile", request.getParameter("aCurrentMemberMobile"));
            model.addAttribute("userguid", request.getParameter("aUserGuid"));
            model.addAttribute("username", request.getParameter("aUserName"));
        }
        request.setAttribute("uplodaUrl", "http://ynwx.yungov.cn/storage/upload");
        request.setAttribute("confirmUrl", configInfo.getServiceInterfaceAddress() + "/apphub/report");
        model.addAttribute("listCrType", weixinQueryService.selectCrtype("dict_crtype"));
        if("1".equals(getWxMemberSession().getIdentifystatus())){
            model.addAttribute("aliasNameWjb", getWxMemberSession().getAliasName());
            model.addAttribute("telephoneWjb", getWxMemberSession().getMobile());
        }
        mv.setViewName("weixin/weixinquery/wxjbxsjbym");
        return mv;


    }

    /**
     * 保存微信举报-线索举报信息
     */
    @ResponseBody
    @RequestMapping(value = "savewxjbxsjb", method = GET)
    public Object savewxjbxsjb(HttpServletRequest request) throws Exception {
        ComplaintReport complaintReport = new ComplaintReport();
        complaintReport.setGuid(request.getParameter("guid").toString());//获得guid
        complaintReport.setContact(request.getParameter("xm").toString());
        complaintReport.setTemp2(request.getParameter("sjhm").toString());
        complaintReport.setUserCode(request.getParameter("sfzhm").toString());
        complaintReport.setAddress(request.getParameter("jtzz").toString());
        String u = URLDecoder.decode(request.getParameter("bt"), "utf-8");
        System.out.println(request.getParameter("bt") + "+++++++++++++++++++++++++++==" + u + "################3");
        complaintReport.setCrTitle(request.getParameter("bt").toString());
        complaintReport.setCrContent(request.getParameter("jbnr").toString());
        complaintReport.setCrType(Integer.valueOf(request.getParameter("wxjblx").toString()));
        complaintReport.setXsly(request.getParameter("xsly").toString());
//          complaintReport.setUserGuid(getWxMemberSession().getGuid());
        complaintReport.setUserGuid("");
        complaintReport.setDeptId("230600000000");
        complaintReport.setDeptName("大庆市公安局");
        complaintReport.setTemp7(request.getParameter("temp7").toString());//类型
        complaintReport.setCreateDate(new Date());//微信端线索举报时间
        return JSONObject.parseObject("{'guid':'" + weixinQueryService.savewxjbxsjb(complaintReport) + "'}");
    }

    /**
     * 保存微信举报-线索举报信息
     */
    @ResponseBody
    @RequestMapping(value = "saveytwxjbxsjb", method = GET)
    public Result saveytwxjbxsjb(HttpServletRequest request) throws Exception {

        return weixinQueryService.saveytwxjbxsjb(request);
    }


    /**
     * 微信随手拍功能
     */


    /**
     * 跳转到微信举报-城区禁放烟花爆竹举报页面
     */
    @RequestMapping(value = "wxjbjfyhbzym", method = GET)
    public ModelAndView gotowxjbjfyhbzym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("aliasName", getWxMemberSession().getAliasName());
        mv.addObject("telephone", getWxMemberSession().getUserName());
        mv.setViewName("weixin/weixinquery/wxjbjfyhbzym");
        return mv;
    }

    /**
     * 保存微信举报-城区禁放烟花爆竹举报信息
     */
    @ResponseBody
    @RequestMapping(value = "savewxjbjfyhbz", method = GET)
    public Object savewxjbjfyhbz(HttpServletRequest request) throws Exception {
        ComplaintReport complaintReport = new ComplaintReport();
        complaintReport.setUserName(request.getParameter("xm").toString());
        complaintReport.setTemp2(request.getParameter("sjhm").toString());
        complaintReport.setAddress(request.getParameter("address").toString());
        complaintReport.setCrType(Integer.valueOf(request.getParameter("wxjblx").toString()));
        complaintReport.setXsly(request.getParameter("xsly").toString());
        complaintReport.setUserGuid(getWxMemberSession().getGuid());
        complaintReport.setDeptId("211300310000");
        complaintReport.setDeptName("辽宁省大庆市公安局指挥中心");
        complaintReport.setCrTitle(" ");
        complaintReport.setCrContent(" ");
        return JSONObject.parseObject("{'guid':'" + weixinQueryService.savewxjbjfyhbz(complaintReport) + "'}");
    }

    /**
     * 跳转到微信举报-公交车抓小偷举报页面
     */
    @RequestMapping(value = "wxjbgjcym", method = GET)
    public ModelAndView gotowxjbgjcym() throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("aliasName", getWxMemberSession().getAliasName());
        mv.addObject("telephone", getWxMemberSession().getUserName());
        mv.setViewName("weixin/weixinquery/wxjbgjcym");
        return mv;
    }

    /**
     * 保存微信举报-公交车抓小偷举报信息
     */
    @ResponseBody
    @RequestMapping(value = "savewxjbjgjczxt", method = GET)
    public Object savewxjbjgjczxt(HttpServletRequest request) throws Exception {
        ComplaintReport complaintReport = new ComplaintReport();
        complaintReport.setUserName(request.getParameter("xm").toString());
        complaintReport.setTemp2(request.getParameter("sjhm").toString());
        complaintReport.setGjxx(request.getParameter("gjxx").toString());
        complaintReport.setCrType(Integer.valueOf(request.getParameter("wxjblx").toString()));
        complaintReport.setXsly(request.getParameter("xsly").toString());
        complaintReport.setUserGuid(getWxMemberSession().getGuid());
        complaintReport.setDeptId("211300310000");
        complaintReport.setDeptName("辽宁省大庆市公安局指挥中心");
        complaintReport.setCrTitle(" ");
        complaintReport.setCrContent(" ");
        return JSONObject.parseObject("{'guid':'" + weixinQueryService.savewxjbjgjczxt(complaintReport) + "'}");
    }

    /**
     * 跳转到机动车驾驶证基本信息查询页面
     */
    @RequestMapping(value = "jdcjszjbxxym", method = GET)
    public ModelAndView gotojdcjszjbxxym(HttpServletRequest request) throws Exception {
        ModelAndView mv = new ModelAndView();
        mv.addObject("pushId", request.getParameter("pushId").toString());
        mv.addObject("pushType", request.getParameter("pushType").toString());
        mv.setViewName("weixin/weixinquery/jdcjszjbxxym");
        return mv;
    }

    /**
     * 绑定车辆
     *
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "bdcl", method = GET)
    public Result bdcl(HttpServletRequest request) throws Exception {
//        String guid = request.getParameter("guid").toString();
//        String hyzk = request.getParameter("hyzk").toString();
//        String mz = request.getParameter("mz").toString();

        return weixinQueryService.bdcl();
    }

    /**
     * 绑定驾驶证
     *
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "bdjsz", method = GET)
    public Result bdjsz(HttpServletRequest request) throws Exception {
        return weixinQueryService.bdjsz(request);
    }

    @ResponseBody
    @RequestMapping(value = "bcclxx", method = GET)
    public boolean bcclxx(HttpServletRequest request) throws Exception {
        String guid = request.getParameter("guid").toString();
//        String hyzk = request.getParameter("hyzk").toString();
//        String mz = request.getParameter("mz").toString();
        String jg = request.getParameter("jg").toString();
        String xl = request.getParameter("xl").toString();
        return weixinQueryService.bcclxx(guid, "", "", jg, xl);
    }


    /**
     * 我的局长信箱
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "myJzxx", method = POST)
    public Result gotoMyJzxx(HttpServletRequest request) {
        String guid = request.getParameter("guid").toString();
        String status = request.getParameter("status").toString();
        return new Result(Result.SUCC, weixinQueryService.getjzxx(guid, status));
    }

    /**
     * 跳转到我的局长信箱详情页面
     */
    @RequestMapping(value = "myjzxxxq/{xjno}/{guid}", method = GET)
    public String goToMyjzxxxq(@PathVariable String xjno, @PathVariable String guid, Model model) {
        Tsjy tsjy = weixinQueryService.getjzxxxq(guid, xjno);
        model.addAttribute("tsjy", tsjy);
        return "weixin/order/myJzxx_detail";
    }


    /**
     * 进入网上办件进度查询页面
     *
     * @return
     */
    @RequestMapping(value = "gotoBjjdCx", method = GET)
    public ModelAndView gotoBjjdPage(ModelMap modelMap) {
        return new ModelAndView("weixin/bmsrv/bjcx");

    }


    /**
     * 进入机动车违法查询页面
     *
     * @return
     */
    @RequestMapping(value = "gotoJdcwfCx", method = GET)
    public ModelAndView gotoJdcwPage(ModelMap modelMap) throws Exception {
        modelMap.addAttribute("listClwzType",weixinQueryService.selectCrtype("dic.vehicleType"));
        return new ModelAndView("weixin/bmsrv/wfcx_jdcwf");

    }

    /**
     * 进入驾驶证记分查询页面
     *
     * @return
     */
    @RequestMapping(value = "gotoJszjfCx", method = GET)
    public ModelAndView gotoJszjfPage(ModelMap modelMap) {
        return new ModelAndView("weixin/bmsrv/wfcx_jszjf");
    }

    /**
     * 进入重名查询页面
     *
     * @return
     */
    @RequestMapping(value = "gotoCmCx", method = GET)
    public ModelAndView gotoCmPage(ModelMap modelMap,HttpServletRequest request) {
        modelMap.addAttribute("type",request.getParameter("type"));
        modelMap.addAttribute("cName",request.getParameter("cName"));
        modelMap.addAttribute("appid",  WxFactory.APPID);
        GetSignatureResponse signature = WxFactory.buildJsAPI().getSignature(WxFactory.CMCX);
        modelMap.addAttribute("timestamp",  signature.getTimestamp());
        modelMap.addAttribute("noncestr",   signature.getNoncestr());
        modelMap.addAttribute("signature",  signature.getSignature());
        return new ModelAndView("weixin/bmsrv/cmcx");
    }

    /**
     * 进入堵路移车页面
     *
     * @return
     */
    @RequestMapping(value = "gotoDlyc", method = GET)
    public ModelAndView gotoDlycPage(ModelMap modelMap, HttpServletRequest request) throws IOException {
        request.setAttribute("uplodaUrl", "http://ynwx.yungov.cn/storage/upload");
        modelMap.addAttribute("listVehicleType",weixinQueryService.selectCrtype("dic.vehicleType"));
        // 微信端
        if( "W".equals(request.getParameter("pt"))){
            modelMap.addAttribute("pt",request.getParameter("pt"));
            if(null!=getWxMemberSession()) {
                return new ModelAndView("weixin/bmsrv/dlyc");
            }else {
                OauthAPI oauthAPI = WxFactory.buildOauthAPI();
                return new ModelAndView("redirect:" + oauthAPI.getOauthPageUrl(WxFactory.PERCENTER_OAUTH_URL, OauthScope.SNSAPI_BASE, "123"));
            }
        }else {//App端
            modelMap.addAttribute("aUserGuid",request.getParameter("userguid"));
            modelMap.addAttribute("aUserName",request.getParameter("username"));
            modelMap.addAttribute("pt",request.getParameter("pt"));
            return new ModelAndView("weixin/bmsrv/dlyc");
        }
    }

    /**
     * 进入EMS查询页面
     *
     * @return
     */
    @RequestMapping(value = "gotoEmsCx", method = GET)
    public ModelAndView gotoEmsCxPage(ModelMap modelMap) {
        return new ModelAndView("weixin/bmsrv/emscx");
    }


    /**
     * 出入境 办理进度查询
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getEntry",method = POST)
    public Result getEntry(HttpServletRequest request){
        return weixinQueryService.getEntry(request);
    }
}
